package com.ohos.connect.devicecloud.app.modular.project.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.ohos.connect.devicecloud.app.modular.project.model.vo.ProjectVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.ohos.connect.devicecloud.common.annotation.CommonLog;
import com.ohos.connect.devicecloud.common.pojo.CommonResult;
import com.ohos.connect.devicecloud.app.modular.project.model.entity.Project;
import com.ohos.connect.devicecloud.app.modular.project.model.dto.ProjectAddDTO;
import com.ohos.connect.devicecloud.app.modular.project.model.dto.ProjectEditDTO;
import com.ohos.connect.devicecloud.app.modular.project.model.dto.ProjectIdDTO;
import com.ohos.connect.devicecloud.app.modular.project.service.ProjectService;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * APP项目控制器
 *
 * @author Dongtao
 * @date  2024/12/05 10:46
 */
@Api(tags = "项目接口")
@ApiSupport(author = "OHOS_CONNECT_TEAM", order = 2)
@RestController
@RequestMapping(value = "/api/v1/device_cloud/app/project")
@Validated
public class ProjectController {

    @Resource
    private ProjectService projectService;

    /**
     * 获取APP项目分页
     *
     * @author Dongtao
     * @date  2024/12/05 10:46
     */
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "获取项目列表")
    @GetMapping("/list")
    public CommonResult<List<ProjectVO>> projectList() {
        return CommonResult.data(projectService.getProjectListByAppUser());
    }

    /**
     * 添加APP项目
     *
     * @author Dongtao
     * @date  2024/12/05 10:46
     */
    @ApiOperationSupport(order = 2)
    @ApiOperation("添加项目")
    @CommonLog("添加项目")
    @PostMapping("/add")
    public CommonResult<Boolean> add(@RequestBody @Valid ProjectAddDTO projectAddDTO) {
        return CommonResult.data(projectService.add(projectAddDTO));
    }

    /**
     * 编辑APP项目
     *
     * @author Dongtao
     * @date  2024/12/05 10:46
     */
    @ApiOperationSupport(order = 3)
    @ApiOperation("编辑项目")
    @CommonLog("编辑项目")
    @PostMapping("/edit")
    public CommonResult<Boolean> edit(@RequestBody @Valid ProjectEditDTO projectEditDTO) {
        return CommonResult.data(projectService.edit(projectEditDTO));
    }

    /**
     * 删除APP项目
     *
     * @author Dongtao
     * @date  2024/12/05 10:46
     */
    @ApiOperationSupport(order = 4)
    @ApiOperation("删除项目")
    @CommonLog("删除项目")
    @PostMapping("/delete")
    public CommonResult<Boolean> delete(@RequestBody @Valid ProjectIdDTO projectIdDTO) {
        return CommonResult.data(projectService.deleteById(projectIdDTO.getId()));
    }

    /**
     * 获取APP项目详情
     *
     * @author Dongtao
     * @date  2024/12/05 10:46
     */
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "获取项目详情",hidden = true)
    @GetMapping("/detail")
    public CommonResult<Project> detail(@Valid ProjectIdDTO projectIdDTO) {
        return CommonResult.data(projectService.detail(projectIdDTO));
    }
}
